package com.livce.controller;

import com.livce.entity.Livecommerce;
import com.livce.service.LivecommerceService;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/13  15:43
 */
@Controller
public class LivecommerceController {
    Logger logger= LoggerFactory.getLogger(LivecommerceController.class);

    @Autowired
    LivecommerceService livecommerceService;

    @RequestMapping("/list") //访问路径
    public String list(Model model){
        List<Livecommerce> list=new ArrayList<>();
        list=livecommerceService.selectAll();
        model.addAttribute("list",list);
        return "list"; //查找jsp存在的文件名
    }

    @RequestMapping("/add")
    public String add(){
        return "add";
    }

    @RequestMapping("/save")
    public String save(Livecommerce livecommerce){
        int count=livecommerceService.insert(livecommerce);
        if(count>0){
            return "redirect:/list";
        }
        return "redirect:/list";
    }

    @RequestMapping("/detail")
    public String detail(@RequestParam("id") int id, Model model){
        Livecommerce livecommerce=livecommerceService.selectById(id);
        model.addAttribute("livecommerce",livecommerce);
        return "userdetail";
    }
}
